package com.zry.fertilizer.retrofit

import android.content.Context
import android.util.Log
import com.zry.fertilizer.been.LongAndShortCode
import com.zry.fertilizer.retrofit.dialog.ProgressSubscriber
import com.zry.fertilizer.utils.ToastUtil


class HttpServer(private val showUserView: ShowUserView) : ApiSupport {
    /**
     * 用户登录
     */
    fun loginApi(username: String, password: String,juris:String, context: Context) {
        execute(api.loginApi(username, password,juris), ProgressSubscriber({ httpResponse ->
            Log.e("TAG", httpResponse.toString())
            showUserView.toMainActivity(0, httpResponse)
        }, context))
    }

    /**
     * 获取产品信息
     */
    fun getProductList(enterpriseId: String, context: Context) {
        execute(api.GetProductList(enterpriseId), ProgressSubscriber({ productInfoList ->
            Log.e("TAG", productInfoList.toString())
            showUserView.toMainActivity(1, productInfoList)
        }, context))
    }

    /**
     * 获取生产批次
     */
    fun getBatchByProductId(productId: String, context: Context) {
        execute(api.GetBatchByProductId(productId), ProgressSubscriber({ batchInfoList ->
            Log.e("TAG", batchInfoList.toString())
            showUserView.toMainActivity(2, batchInfoList)
        }, context))
    }

    /**
     * 获取生产线
     */
    fun getProductionLine(enterpriseId: String, context: Context) {
        execute(api.GetProductionLine(enterpriseId), ProgressSubscriber({ productLineList ->
            Log.e("TAG", productLineList.toString())
            showUserView.toMainActivity(3, productLineList)
        }, context))
    }

    /**
     * 获取装箱单位列表
     */
    fun getPackList(context: Context) {
        execute(api.GetPackList(), ProgressSubscriber({ packList ->
            Log.e("TAG", packList.toString())
            showUserView.toMainActivity(4, packList)
        }, context))
    }


    /**
     * 获取长追溯码
     */
    fun getLongTraceCode(shortCode: String, context: Context) {
        execute(api.GetCodeID(shortCode), ProgressSubscriber({ resultCode ->
            if (resultCode.state == "1") {
                showUserView.toMainActivity(5, LongAndShortCode(resultCode.CodeID, shortCode))
            } else {
                ToastUtil.toast(context, "扫码失败")
            }
        }, context))
    }

    /**
     * 获取长流通码
     */
    fun getLongCirculationCode(shortCode: String, context: Context) {
        execute(api.GetFlowCode(shortCode), ProgressSubscriber({ resultFlowCode ->
            if (resultFlowCode.state == "1") {
                showUserView.toMainActivity(6, LongAndShortCode(resultFlowCode.Code, shortCode))
            } else {
                ToastUtil.toast(context, "扫码失败")
            }
        }, context))
    }

    /**
     * 批量打包
     */
    fun postAddLiangFlow(level: String, ProductID: String, UnitID: String, SonCodeNum: String, CodeS: String, UserID: String, EnterpriseID: String, context: Context) {
        execute(api.AddLiangFlow(level, ProductID, UnitID, SonCodeNum, CodeS, UserID, EnterpriseID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(7, resultData)
        }, context))
    }


    /**
     * 获取打包记录
     */
    fun getFlowCodeList(EnterpriseID: String, CreateUserID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetFlowCodeList(EnterpriseID, CreateUserID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(8, resultData)
        }, context))
    }

    /**
     * 获取打包详情
     */
    fun getFlowCodeDetailList(FlowCodeID: String, context: Context) {
        execute(api.GetFlowCodeDetailList(FlowCodeID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(9, resultData)
        }, context))
    }


    /**
     * 号段打包
     */
    fun addDuanFlow(level: String, ProductID: String, UnitID: String, SonCodeNum: String, MaxCode: String, MinCode: String, UserID: String, EnterpriseID: String, context: Context) {
        execute(api.AddDuanFlow(level, ProductID, UnitID, SonCodeNum, MaxCode, MinCode, UserID, EnterpriseID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(10, resultData)
        }, context))
    }

    /**
     * 获取订单列表
     */
    fun getStoreOrderList(EnterpriseID: String, pageIndex: Int, pageSize: Int, ProductID: String, OrderState: String,OrderCode:String, context: Context) {
        execute(api.GetStoreOrderList(EnterpriseID, pageIndex, pageSize, ProductID, OrderState,OrderCode), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(11, resultData)
        }, context))
    }

    /**
     * 批量入库
     */
    fun addLiangStore(OrderID: String, CodeS: String, StoreDate: String, UserID: String, context: Context) {
        execute(api.AddLiangStore(OrderID, CodeS, StoreDate, UserID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(12, resultData)
        }, context))
    }

    /**
     * 号段入库
     */
    fun addDuanStore(OrderID: String, MaxCode: String, MinCode: String, StoreDate: String, UserID: String, context: Context) {
        execute(api.AddDuanStore(OrderID, MaxCode, MinCode, StoreDate, UserID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(13, resultData)
        }, context))
    }

    /**
     * 入库记录
     */
    fun getStoreDetailList(CreateUserID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetStoreDetailList(CreateUserID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(14, resultData)
        }, context))
    }

    /**
     * 入库记录详情
     */
    fun getStoreDetailInfo(DetailID: String, context: Context) {
        execute(api.GetStoreDetailInfo(DetailID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(15, resultData)
        }, context))
    }

    /**
     * 出库订单列表
     */
    fun getOutStockList(EnterpriseID: String, pageIndex: Int, pageSize: Int, CustomerID: String, StateID: String, OutCode: String, context: Context) {
        execute(api.GetOutStockList(EnterpriseID, pageIndex, pageSize, CustomerID, StateID, OutCode), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(16, resultData)
        }, context))
    }

    /**
     * 批量出库
     */
    fun addLiangOutStockDetail(OutStockID: String, ProductID: String, OutLevel: String, CodeS: String,
                               CreateUserID: String, EnterpriseID: String, context: Context) {
        execute(api.AddLiangOutStockDetail(OutStockID, ProductID, OutLevel, CodeS, CreateUserID, EnterpriseID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(17, resultData)
        }, context))
    }

    /**
     * 号段出库
     */

    fun addDuanOutStockDetail(OutStockID: String, ProductID: String, OutLevel: String, MinCode: String, MaxCode: String,
                              CreateUserID: String, EnterpriseID: String, context: Context) {
        execute(api.AddDuanOutStockDetail(OutStockID, ProductID, OutLevel, MinCode, MaxCode, CreateUserID, EnterpriseID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(18, resultData)
        }, context))
    }

    /**
     * 获取出库记录列表
     */
    fun getOutDetailList(CreateUserID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetOutDetailList(CreateUserID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(19, resultData)
        }, context))
    }


    /**
     * 获取出库记录详情
     */
    fun getOutDetailInfo(DetailID: String, context: Context) {
        execute(api.GetOutDetailInfo(DetailID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(20, resultData)
        }, context))
    }

    /**
     * 根据流通吗获取产品信息
     */
    fun getFlowCodeInfo(CodeID: String, context: Context) {
        execute(api.GetFlowCodeInfo(CodeID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(21, resultData)
        }, context))
    }

    /**
     * 补码入箱
     */
    fun complementFlow(CodeID: String, SonCode: String, EnterpriseID: String, CreateUserID: String, context: Context) {
        execute(api.ComplementFlow(CodeID, SonCode, EnterpriseID, CreateUserID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(22, resultData)
        }, context))
    }

    /**
     * 拆码出箱
     */
    fun dismantlingFlow(CodeID: String, SonCode: String, EnterpriseID: String, CreateUserID: String, context: Context) {
        execute(api.DismantlingFlow(CodeID, SonCode, EnterpriseID, CreateUserID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(23, resultData)
        }, context))
    }

    /**
     * 补码、拆码记录列表
     */

    fun getFlowRecordList(CreateUserID: String, EnterpriseID: String, StateID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetFlowRecordList(CreateUserID, EnterpriseID, StateID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(24, resultData)
        }, context))
    }

//    /**
//     * 补码、拆码详情
//     */
//    fun getFlowRecordInfo(RecordID: String, context: Context) {
//        execute(api.GetFlowRecordInfo(RecordID), ProgressSubscriber({ resultData ->
//            showUserView.toMainActivity(25, resultData)
//        }, context))
//    }

    /**
     * 判断当前是否有新版本
     */
    fun checkApp(vNumber: String, VersionType: String, context: Context) {
        execute(api.checkApp(vNumber, VersionType), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(26, resultData)
        }, context))
    }


    /**
     * App新接口
     */
    /**
     * 获取产品信息
     */
    fun getProductByProductNameList(EnterpriseID: String, ProName: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetProductByProductNameList(EnterpriseID, ProName, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(27, resultData)
        }, context))
    }

    /**
     * 获取溯源录入列表
     */
    fun getBatchAllList(EnterpriseID: String, Pid: String, bid: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetBatchAllList(EnterpriseID, Pid, bid, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(28, resultData)
        }, context))
    }

    /**
     * 获取批次详情
     */
    fun getBatchInfo(bid: String, context: Context) {
        execute(api.GetBatchInfo(bid), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(29, resultData)
        }, context))
    }

    /**
     * 获取模板列表
     */
    fun onLoadingBatchModel(EnterpriseID: String, ProductID: String, context: Context) {
        execute(api.OnLoadingBatchModel(EnterpriseID, ProductID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(30, resultData)
        }, context))
    }

    /**
     * 提交创建模板数据
     */
    fun addBatchInfo(EnterpriseID: String, CreateUserID: String, BatchName: String, ProductID: String, ModelID: String, context: Context) {
        execute(api.AddBatchInfo(EnterpriseID, CreateUserID, BatchName, ProductID, ModelID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(31, resultData)
        }, context))
    }

    /**
     * 获取订单详情
     */
    fun getStoreOrderInfo(OrderID: String, context: Context) {
        execute(api.GetStoreOrderInfo(OrderID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(32, resultData)
        }, context))
    }

    /**
     * 结单
     */
    fun finishOrderInfo(OrderID: String, remark: String, CreateUserID: String, context: Context) {
        execute(api.FinishOrderInfo(OrderID, remark, CreateUserID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(33, resultData)
        }, context))
    }

    /**
     * 获取经销商列表
     */
    fun getCustomerList(EnterpriseID: String, CustomerName: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetCustomerList(EnterpriseID, CustomerName, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(34, resultData)
        }, context))
    }

    /**
     * 获取经销商详情
     */
    fun outStockInfo(OutID: String, context: Context) {
        execute(api.OutStockInfo(OutID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(35, resultData)
        }, context))
    }

    /**
     * 获取出库清单
     */
    fun getOutStockDetailList(OutID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetOutStockDetailList(OutID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(36, resultData)
        }, context))
    }

    /**
     * 获取经销商详情
     */
    fun getCustomerInfo(CustomerID: String, context: Context) {
        execute(api.GetCustomerInfo(CustomerID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(37, resultData)
        }, context))
    }

    /**
     * 获取库存产品列表
     */
    fun productReport(EnterpriseID: String, pageIndex: Int, pageSize: Int, ProductName: String, context: Context) {
        execute(api.ProductReport(EnterpriseID, pageIndex, pageSize, ProductName), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(38, resultData)
        }, context))
    }

    /**
     * 追溯码查询详情
     */
    fun getCodeInfo(Code: String, context: Context) {
        execute(api.GetCodeInfo(Code), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(39, resultData)
        }, context))
    }

    /**
     * 追溯码查询详情
     */
    fun getFlowCodeByCodeInfo(Code: String, context: Context) {
        execute(api.GetFlowCodeByCodeInfo(Code), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(40, resultData)
        }, context))
    }

    /**
     * 溯源录入提交节点信息
     */
    fun addDetailOperaInfo(OperaID: String, DetailID: String, ModelID: String, OperaName: String, OperaDate: String,
                           Remark: String, ProvinceName: String, CityName: String, AreaName: String, Address: String,
                           EnterpriseID: String, CreateUserID: String, BatchID: String, context: Context) {
        execute(api.AddDetailOperaInfo(OperaID, DetailID, ModelID, OperaName, OperaDate,
                Remark, ProvinceName, CityName, AreaName, Address, EnterpriseID, CreateUserID, BatchID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(41, resultData)
        }, context))
    }

    /**
     * 发送消息列表
     */
    fun getNoticeList(pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetNoticeList(pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(42, resultData)
        }, context))
    }

    /**
     *接收通知
     */
    fun getNoticeUserList(CreateUserID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetNoticeUserList(CreateUserID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(43, resultData)
        }, context))
    }

    /**
     * 获取通知信息详情
     */
    fun getNoticeInfo(NoticeID: String, context: Context) {
        execute(api.GetNoticeInfo(NoticeID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(44, resultData)
        }, context))
    }
}
